var basePath='http://localhost:8080/';
var oldPhotoNum=0;
$(function(){
	initOrderInfo($("#fixOrderId").html());
	initUpload();
});
//初始化订单信息
function initOrderInfo(orderId){
	$.ajax({
		url:'fixOrder/getInfo',
		method:'get',
		dataType:'json',
		data:{
			fixOrderId:orderId,
		},
		success:function(data){
			if(data.code==0){
				setOrderInfo(data.row);
			}
			else{
				alert('获取订单信息失败')
			}
		},
		error:function(){
			alert("获取报修信息出现错误")
		}
	})
}
function setOrderInfo(info){
	var fixOrder=info.fixOrder;
	var fileList=info.photoList;
	var handleInfo=info.fixOrderHandle;
	setBaseInfo(fixOrder,fileList);
	if(handleInfo!=null&&handleInfo!=undefined)
	  setHandleInfo(handleInfo);
}
function setBaseInfo(fixOrder,fileList){
	$('#article').val(fixOrder.article);
	$('#description').val(fixOrder.description);
	$('#name').val(fixOrder.name);
	$('#phone').val(fixOrder.phone);
	$('#address').val(fixOrder.address);
	$('#userRemark').val(fixOrder.remark)
	
	for(var i=0;i<fileList.length;i++){
		var item=fileList[i];
		var webPath=basePath+item.path+'/'+item.fileName
		var html='<img src="'+webPath+'" class="photo">';
		var index=i+1;
		$("#photo"+index).parent().find('input[type="hidden"]').val(item.id);
		$("#photo"+index).empty();
		$("#photo"+index).html(html);
		oldPhotoNum++;
	}
}
function setHandleInfo(handleInfo){
	//$('#handleId').val(handleInfo.id);
	var examResult;
	switch(handleInfo.examStatus){
	    case 0:examResult='审核未通过';break;
	    case 1:examResult='审核通过';break;
	    default:examResult='未审核';break;
	};
	if(handleInfo.examStatus==1){
		$('#examResult').html(examResult);
		var isCharge;
		switch(handleInfo.isCharge){
		    case 0:isCharge='不收费';break;
		    case 1:isCharge='收费';break;
		    default:isCharge='未确定';break;
		};
		$('#isCharge').html(isCharge);
		$('#charge').html(handleInfo.charge);
		
		setRepairerInfo(handleInfo.repairerId);
		/*$("#repairer").html(handleInfo.repairerId);*/
		$("#fixTime").html(handleInfo.fixTime);
	}
	$('#handleTime').html(handleInfo.updateTime);
	$('#remark').html(handleInfo.remark);
	
}

//获取并设置工人信息
function setRepairerInfo(workerId){
	$.get('/findWorker/'+workerId,'',function(data){
		if(data.code==0){
			$('#repairer').html(data.row.name);
			$('#repairerPhone').html(data.row.tel);
		}
	});
}
